<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\health\model\HealthBusiness;
use think\Db;
/**
 *  工单系统的接口
 *
 *  Author:  YSX
    Date:    2024-5-16
 */
class Work extends Api
{
    protected $noNeedLogin = ['businessErrorList'];
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }
    /*
     * 列表
    */
    public function businessErrorList()
    {
        // $params = $this->params;
		if (!$this->request->isPost()) {
			return $this->error('提交方式不正确');
		}
		$params = $this->request->post();
		$where['status'] = array('in',[0,-1]);
		// 获取昨天的开始时间
		$yesterdayStart = strtotime("yesterday");
		$startTime = date("Y-m-d H:i:s", $yesterdayStart);
		// $startTime = date('Y-m-d');
		// 获取当天的结束时间戳
		$endOfDayTimestamp = strtotime("tomorrow") - 1;
		 
		// 将结束时间戳格式化为日期时间字符串
		$endTime = date("Y-m-d H:i:s", $yesterdayStart+86399);
		// halt($endTime);
		if(isset($params['start_time ']) || !empty($params['start_time'])){
			$startTime = $params['start_time'];
		}
		if(isset($params['end_time ']) || !empty($params['end_time'])){
			$endTime = $params['end_time'];
		}
        $data = HealthBusiness::where($where)
			->whereTime('created_at', '>=', $startTime)
			->whereTime('created_at', '<=', $endTime)
			->select(); 
		// dump($data);
		// halt(HealthBusiness::getLastSql());
		if ($data) {
			$this->success('获取成功', $data);
		}
		$this->error('请求失败');
    }
}
